package com.ruoyi.voucher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherReversal;
import com.ruoyi.voucher.service.IVoucherReversalService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证红冲记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/voucher_reversal")
public class VoucherReversalController extends BaseController
{
    @Autowired
    private IVoucherReversalService voucherReversalService;

    /**
     * 查询凭证红冲记录列表
     */
    @RequiresPermissions("voucher:voucher_reversal:list")
    @GetMapping("/list")
    public TableDataInfo list(VoucherReversal voucherReversal)
    {
        startPage();
        List<VoucherReversal> list = voucherReversalService.selectVoucherReversalList(voucherReversal);
        return getDataTable(list);
    }

    /**
     * 导出凭证红冲记录列表
     */
    @RequiresPermissions("voucher:voucher_reversal:export")
    @Log(title = "凭证红冲记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherReversal voucherReversal)
    {
        List<VoucherReversal> list = voucherReversalService.selectVoucherReversalList(voucherReversal);
        ExcelUtil<VoucherReversal> util = new ExcelUtil<VoucherReversal>(VoucherReversal.class);
        util.exportExcel(response, list, "凭证红冲记录数据");
    }

    /**
     * 获取凭证红冲记录详细信息
     */
    @RequiresPermissions("voucher:voucher_reversal:query")
    @GetMapping(value = "/{reversalId}")
    public AjaxResult getInfo(@PathVariable("reversalId") Long reversalId)
    {
        return success(voucherReversalService.selectVoucherReversalByReversalId(reversalId));
    }

    /**
     * 新增凭证红冲记录
     */
    @RequiresPermissions("voucher:voucher_reversal:add")
    @Log(title = "凭证红冲记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherReversal voucherReversal)
    {
        return toAjax(voucherReversalService.insertVoucherReversal(voucherReversal));
    }

    /**
     * 修改凭证红冲记录
     */
    @RequiresPermissions("voucher:voucher_reversal:edit")
    @Log(title = "凭证红冲记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherReversal voucherReversal)
    {
        return toAjax(voucherReversalService.updateVoucherReversal(voucherReversal));
    }

    /**
     * 删除凭证红冲记录
     */
    @RequiresPermissions("voucher:voucher_reversal:remove")
    @Log(title = "凭证红冲记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reversalIds}")
    public AjaxResult remove(@PathVariable Long[] reversalIds)
    {
        return toAjax(voucherReversalService.deleteVoucherReversalByReversalIds(reversalIds));
    }
}
